<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Listener;

use App\Utils\Elasticsearch;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Event\Annotation\Listener;
use Hyperf\Event\Contract\ListenerInterface;
use Psr\Container\ContainerInterface;

/**
 * @Listener
 */
class EsInitListener implements ListenerInterface
{
    /**
     * @Inject
     * @var Elasticsearch
     */
    protected $es;

    /**
     * @var ContainerInterface
     */
    private $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    public function listen(): array
    {
        return [
        ];
    }

    public function process(object $event)
    {
//        $initIndex = [
//            [
//                'index' => 'user_diary',
//                'type' => 'diary',
//                'mapping_key' => [
//                    'text' => ['content'],
//                ],
//            ],
//        ];
//        $esClient = $this->es;
//        foreach ($initIndex as $value) {
//            $indexName = $value['index'];
//            $type = $value['type'];
//            $mappingKey = $value['mapping_key'];
//            if (! $esClient->indexExistsEs($indexName)) {
//                $esClient->createIndex($indexName);
//                $esClient->putMapping($indexName, $type, $mappingKey);
//            }
//        }
    }
}
